/* pglpy.i */
 %module pglpy
 %{
#include "../PGLMFC/include/PGLCAPI.h"
 %}

/* Creating type map for flot**/
%typemap(in) float* 
{
	/* Check if is a list */
	if (PyList_Check($input)) 
	{
		int size = PyList_Size($input);	
		int i = 0;
		$1 = (float*) malloc(size*sizeof(float));
		for (i = 0; i < size; i++) 
		{
			PyObject *o = PyList_GetItem($input,i);
			if (PyNumber_Check(o))
				$1[i] = PyFloat_AsDouble(PyList_GetItem($input,i));
			else 
				$1[i] = 0;
		}
	} 
	else if (PyTuple_Check($input))
	{
		int size = PyTuple_Size($input);	
		int i = 0;
		$1 = (float*) malloc(size*sizeof(float));
		for (i = 0; i < size; i++) 
		{
			PyObject *o = PyTuple_GetItem($input,i);
			if (PyNumber_Check(o))
				$1[i] = PyFloat_AsDouble(PyTuple_GetItem($input,i));
			else 
				$1[i] = 0;
		}
	}
	else 
	{
		PyErr_SetString(PyExc_TypeError,"not a list");
		return NULL;
	}
}

// This cleans up the char ** array we malloc'd before the function call
%typemap(freearg) float* 
{
	free((float*) $1);
}

%include "pgl.i"
